Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform end-to-end tests into acceptance tests using Behat with in-memory repos #7209

Closed
wants to merge 5 commits into from

Conversation

phaseinducer
Copy link
Contributor

@phaseinducer phaseinducer commented Nov 24, 2017

This POC is a follow-up to #7157.

The idea is the same : find a way to transform end-to-end tests into other more relevant and efficient types of tests.
The first POC was very naive and pragmatic, this time I wanted to go further and try to use Behat with Symfony integration to be able to use the DI.

About the tests themselves

I chose validation scenarii as a simple (but not so much at the end) work base.
The old tests were end-to-end, they used :

  • UI + controllers + normalizers
  • business code
  • database

The goal was to find a way to focus on the business logic.
First step : rework the Gherkin to remove all notions of UI components and call directly business services from the new Behat context. The UI behavior can still be tested by other end-to-end tests.

About how I reworded the tests : I discussed a lot with @jjanvier and @Delphineray about the fact that it should be possible to validate a value collection without using a product (technically we're really close to be able to do it). Indeed, a value collection could be seen as a standalone entity and can be contained by something else, a product model for instance. So it could make sense even from a functional point of view.
Anyway we didn't find any good solution, it looks like it's still not a well defined concept, or at least we couldn't find a common (technical/functional) way to talk about it.
So for the moment i chose to mention products in the Gherkin, it can change later.

Technical solution

Then, to avoid calling the database I used an in-memory repository when needed (for these use cases only the attribute repository was called).
To do that, I needed :

  • A new Symfony environment, as light as possible, mainly used to replace ORM repos by in-memory repos in the DI.
  • A new Behat profile with a new "acceptance" suite, using this new environment (unfortunately for the moment it's not possible to set a different environment per suite, see Allow setting symfony env per-suite Behat/Symfony2Extension#131)

I also created a brand new Behat context. Still not sure about the naming, the files organisation, the steps design, the stateful behavior, how to split it later... Feel free to propose ideas and vision.

Possible next steps

  • Continue to transform other scenarii and use it to improve the new context(s).
  • Find how to launch it on the CI.
  • Validate it with the POs.

Try it

Launch bin/behat --profile=acceptance --suite=acceptance on your machine.

class: Pim\Test\Common\Persistence\InMemoryAttributeRepository

pim_catalog.repository.attribute:
alias: pim_catalog.saver.attribute
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks weird but I didn't find another way to use the same instance for two different services :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok to me

class: Pim\Test\Common\Persistence\InMemoryAttributeRepository

pim_catalog.repository.attribute:
alias: pim_catalog.saver.attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok to me

@@ -22,6 +22,9 @@
"classmap": [ "app/AppKernel.php", "app/AppCache.php", "tests/AppKernelTest.php" ]
},
"autoload-dev": {
"psr-4": {
"Pim\\Test\\": "tests/"
Copy link
Contributor

@docteurklein docteurklein Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if that was meant only for behat, you could move it in the autoload part of behat.yml (not really important I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be used by something else than Behat imho.

@@ -0,0 +1,27 @@
imports:
Copy link
Contributor

@docteurklein docteurklein Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't see how you decide which kernel environment to use (I guess in your behat.yml ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phaseinducer phaseinducer deleted the poc-behat-in-memory branch February 11, 2019 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants